<?php
/** * Settings_model Class * 
* @package TIAP 
* @subpackage Model 
* @category settings 
* @author Harits Balfas 
* @link http://twitter.com/jeblagsancang 
*/
class Settings_model extends MY_Model{
  var $settings_table;
  
  function Settings_model(){
    parent::MY_Model();
    $this->settings_table='user_settings';
  }  
  
  /**
  * function insert_settings
  * Insert data to table user_settings
  * 
  * @param mixed $user_tiab_id
  * @param mixed $email_alert
  * @param mixed $email_address
  * @param mixed $sms_alert
  * @param mixed $phone_number
  * @param mixed $email_option
  * @param mixed $advertising
  * 
  * @return string query
  */
  function insert_settings($user_tiab_id, $email_alert, $email_address, $sms_alert, $phone_number, $email_option, $advertising, $receive_crime_report){
    
    $insert_array = array(
      'user_tiab_id'        => $user_tiab_id,
      'email_alert'         => $email_alert,
      'email_address'       => $email_address,
      'sms_alert'           => $sms_alert,
      'phone_number'        => $phone_number,
      'contact_preferences' => $email_option,
      'advertising'         => $advertising,
      'receive_crime_report'  => $receive_crime_report,      
    );
    $this->db->insert($this->settings_table, $insert_array);
    return $this->db->last_query();
  }
  
  /**
  *    get_settings method
  *
  *    @description Get the selected value from table user_settings
  *    @param     string $id
  *    @result row array
  */
  
  function get_settings($id){
    $query = $this->db->get_where($this->settings_table, array('user_tiab_id' => $id));             
    return $query->row_array();
  }
    
  /**
  * function update_settings
  * Update data to table user_settings
  * 
  * @param mixed $user_tiab_id
  * @param mixed $email_alert
  * @param mixed $email_address
  * @param mixed $sms_alert
  * @param mixed $phone_number
  * @param mixed $email_option
  * @param mixed $advertising
  * 
  * @return string query
  */
  function update_settings($user_tiab_id, $email_alert, $email_address, $sms_alert, $phone_number, $email_option, $advertising,$receive_crime_report){    
    $update_array = array(        
        'email_alert'           => $email_alert,
        'email_address'         => $email_address,
        'sms_alert'             => $sms_alert,
        'phone_number'          => $phone_number,
        'contact_preferences'   => $email_option,
        'advertising'           => $advertising,            
        'receive_crime_report'  => $receive_crime_report,            
    );    
    $this->db->where('user_tiab_id', $user_tiab_id);
    $this->db->update($this->settings_table , $update_array);
    return $this->db->last_query();
  }
  
  function send_member_email($email, $message, $who_send){
	$config = array(
		'mailtype'=>'html'
    );
    $data = array(                              
        'who_send'=> $who_send,
        'message' => $message
    );
    $email_content = $this->load->view(TEMPLATE_NAME.'/front/mail/member_email',$data, true);
    $this->load->library('email');
    $this->email->initialize($config);
    $this->email->from('noreply@turnitaround.co.za', 'Turn It Around');
    $this->email->to($email);    
    //$this->email->to('agoes.doank@gmail.com', 'general@icreativelabs.com', 'mailbox@icreativelabs.com' );
    //$this->email->reply_to('donations@turnitaround.co.za', 'Turn It Around');
    //$this->email->to('info@turnitaround.co.za');       
    $this->email->subject('Message from member');
    $this->email->message($email_content);                
    $this->email->send();	
  }
}

/* End of file settings_model.php */
/* Location: ./system/application/models/settings_model.php */
